package zero.tech.games.extension.remote;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;

import zero.tech.games.api.RemoteExtension;
import zero.tech.games.common.topic.ProxyAdd;
import zero.tech.games.common.topic.ProxyRebind;
import zero.tech.games.extension.service.api.IExtensionService;

@RestController
public class RemoteExtensionImpl implements RemoteExtension{
	@Autowired
	private IExtensionService extensionService;
	@Override
	public List<Integer> allChilds(int club_id, int uid) {
		return extensionService.getAllSubIds(club_id, uid);
	}
	@Override
	public Map<Integer, Integer> zsCountMap(int club_id,String str) {
		List<Integer> list=JSONObject.parseObject(str, new TypeReference<List<Integer>>() {});
		Map<Integer, Integer> map=new HashMap<Integer, Integer>();
		for(Integer uid:list) {
			int size=extensionService.getZsSubIds(club_id, uid).size();
			map.put(uid, size);
		}
		return map;
	}
	@Override
	public Map<Integer, Integer> fzsCountMap(@RequestParam("club_id") int club_id,@RequestParam("uids_str") String str) {
		List<Integer> list=JSONObject.parseObject(str, new TypeReference<List<Integer>>() {});
		Map<Integer, Integer> map=new HashMap<Integer, Integer>();
		for(Integer uid:list) {
			int size=extensionService.getFzsSubIds(club_id, uid).size();
			map.put(uid, size);
		}
		return map;
	}
	@Override
	public void proxyAdd(ProxyAdd proxyAdd) {
		extensionService.proxyAddDynamic(proxyAdd);		
	}
	@Override
	public void proxyRebind(ProxyRebind proxyRebind) {
		extensionService.proxyAddDynamic(proxyRebind);		
	}

}
